<template>
    <view class="home-contirner">
        <u-button type="primary" @click="addCategory">添加分类</u-button>
        <u-cell-group>
            <u-cell-item v-for="(item, key) in dataList" :key="key" :title="item.name"
                @click="editCategory(item)"></u-cell-item>
        </u-cell-group>
    </view>
</template>


<script lang="ts" setup>
import { ref, onMounted } from 'vue';
import config from '../../../config/index'

const dataList = ref([]);
const addCategory = () => {
    uni.navigateTo({
        url: '/pages/create-category/index',
    })
}

const editCategory = (item) => {
    uni.navigateTo({
        url: `/pages/modify-category/index?id=${item.id}`,
        
    })
}

const getDataList = async () => {
    const resp = await uni.request({
        url: `${config.baseUrl}/category/list`,
        method: 'get'
    })
    dataList.value = resp.data.data
}

onMounted(() => {
    getDataList();
})
</script>

<style lang="scss" scoped>
.home-contirner {
    margin: 10rpx;

}
</style>